package com.wrq.utils;

import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.wrq.dto.MessageParamDto;
import com.wrq.enums.MessageTypeEnum;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * Created by hushuyan on 2022/3/19.
 */
@Slf4j
public class TencentMsgUtil {


    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static boolean sendMessage (MessageParamDto paramDto) throws Exception {
        String code="";
        com.aliyun.dysmsapi20170525.Client client = TencentMsgUtil.createClient("LTAI5tCEdjwXf6epbiBa33FS", "GKjeCRhJyeySitB6XSE4SNZSVtMn1i");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(paramDto.getPhone())
                .setSignName("hu666online")
                .setTemplateCode("SMS_235817765")
                .setTemplateParam(paramDto.toString());
        RuntimeOptions runtime = new RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
            code = sendSmsResponse.body.code;
            System.out.println("code: "+ code);
        } catch (TeaException error) {
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }

        if (code.equals("OK")){
            return true;
        }
        return false;
        /* 尊敬的用户，您所打印文件{1}被打印店{2}拒绝，原因为：{3}，如果有疑问请联系{4} */

    }

}
